package com.Main;
import java.io.IOException;

import org.asteriskjava.live.AsteriskChannel;
import org.asteriskjava.live.AsteriskQueueEntry;
import org.asteriskjava.live.AsteriskServer;
import org.asteriskjava.live.AsteriskServerListener;
import org.asteriskjava.live.DefaultAsteriskServer;
import org.asteriskjava.live.MeetMeUser;
import org.asteriskjava.live.internal.AsteriskAgentImpl;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.ManagerEventListener;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.StatusAction;
import org.asteriskjava.manager.event.HangupEvent;
import org.asteriskjava.manager.event.ManagerEvent;

public class HelloEvents implements AsteriskServerListener
{
    private ManagerConnection managerConnection;
    AsteriskServer asserver;
    public HelloEvents() throws IOException
    {
         asserver = new DefaultAsteriskServer("192.168.56.101", "mihira", "pentium");
        
        
    }

    public void run() throws IOException, AuthenticationFailedException,
            TimeoutException, InterruptedException
    {
        // register for events
       
    	asserver.addAsteriskServerListener(this);
    	
      
    	
        // wait 10 seconds for events to come in
        Thread.sleep(100000);

        // and finally log off and disconnect
        managerConnection.logoff();
        
        
    }

    

    
    public void onManagerEvent(ManagerEvent event)
    {
        // just print received events
    	
    	
       
    }

    public static void main(String[] args) throws Exception
    {
        HelloEvents helloEvents;

        helloEvents = new HelloEvents();
        helloEvents.run();
    }

	@Override
	public void onNewAsteriskChannel(AsteriskChannel channel) {
		
		System.out.println("New Channeldsdfads");
		System.out.println("New Channeldsdfads");
		channel.setVariable("extension", "995");
		
	}

	@Override
	public void onNewMeetMeUser(MeetMeUser user) {
		//System.out.println("New Channel");
		
	}

	@Override
	public void onNewAgent(AsteriskAgentImpl agent) {
		//System.out.println("New Channel");
		
	}

	@Override
	public void onNewQueueEntry(AsteriskQueueEntry entry) {
		//System.out.println("New Channel");
		
	}
}